#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: data_copy_source_node.py 
@version:
@time: 2022/03/10 
"""
from TapClientCore.T03_api_body_templates.v2_api_body import DATAFLOW_STAGE_SOURCE_NODE
from TapClientCore.T04_logic.Dag02.node.node_base import NodeBase


class DataCopySourceNode(NodeBase):
    node = None

    def __init__(self, datasource_name):
        self.generate_node(datasource_name)

    def generate_node(self, datasource_name):
        self.node = DATAFLOW_STAGE_SOURCE_NODE.copy()
        from TapClientCore.T05_TM_feature.v2.TMF01_datasource.tmf_http import TMFHttp
        TMF = TMFHttp()
        # 通过datasource名称获取信息
        response = TMF.get_data_source_by_name(datasource_name)
        node = {
            'id': self.newId,
            'database_type': response['database_type'],
            'connectionId': response['id'],
            'name': response['name'],
            'type': 'database',
        }
        if response.get('mqType'):
            node['mqType'] = response.get('mqType')
        self.node.update(node)


if __name__ == '__main__':
    t = DataCopySourceNode('auto_mysql')
    from pprint import pprint

    pprint(t.node)
